var RouterBuilder = require('../')

function routerTester (config, routeOpts) {
  config = config || [
    'pathA/:pathAId/pathB/:pathBId',
    'replaceA/:replaceAId/replaceB/:replaceBId',
  ['repalceUltra/replaceA/replaceB', {namespace: {replaceB: 'anthorChangedB'}}],
  ['urlExtra', {url: 'anchorUrl.com'}],
    'empty/:a/:b/:c/:d/:e/:f/:g'
  ]

  routeOpts = routeOpts || {url: 'url.com', namespace: {replaceA: 'changedA', replaceB: 'changedB'}}

  var Routes
  var args = ['argA', 'argB', 'argC', 'argD', 'argE', 'argF']
  var opts = {format: 'json', anchor: 'anchor'}
  console.log('--- config ---')
  console.log(config)
  console.log('--- options ---')
  console.log(routeOpts)
  console.log('--- client  without opts ---')
  Routes = new RouterBuilder(config, routeOpts)
  for (var cr in Routes.value()) {
    try {
      console.log(cr, '(' + args.join(', ') + ')', '=>', Routes.Routes[cr](...args))
    } catch (e) {
      console.error(e.message)
    }
  }
  console.log('--- client  with opts ---')
  for (var wcr in Routes.value()) {
    try {
      console.log(wcr, '(' + args.join(', ') + ', ' + JSON.stringify(opts) + ')', '=>', Routes.Routes[wcr](...args, opts))
    } catch (e) {
      console.log(e)
    }
  }

  console.log('--- server ---')
  Routes = new RouterBuilder(config, Object.assign(routeOpts, {isServer: true}))
  for (var sr in Routes.value()) {
    console.log(sr + ' () => ', Routes.Routes[sr]())
  }
}

module.exports = routerTester
